package cn.cmkj.auction.data.http;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import cn.cmkj.auction.app.Urls;

/**
 * Created by cunguoyao on 2017/12/22.
 */

public class MainAdvertise implements Serializable {

    public long adv_sub_id;
    public long adv_position_id;
    public String adv_sub_name;
    public String adv_sub_content;
    public String adv_sub_memo;
    public String link_sub_url;
    public String images;
    public long start_time;
    public long end_time;
    public int is_used;
    public long add_time;
    public String add_user;
    public long update_time;
    public String update_user;
    public String url;

    public static List<MainAdvertise> parseJsonArray(JSONArray jsonArray) {
        List<MainAdvertise> list = new ArrayList<>();
        if(jsonArray != null && jsonArray.length() > 0){
            for(int i=0;i<jsonArray.length();i++){
                list.add(parseFromJson(jsonArray.optJSONObject(i)));
            }
        }
        return list;
    }

    public static MainAdvertise parseFromJson(JSONObject json) {
        if(json == null)return null;
        MainAdvertise bean = new MainAdvertise();
        bean.adv_sub_id = json.optLong("adv_sub_id", 0);
        bean.adv_position_id = json.optLong("adv_position_id", 0);
        bean.adv_sub_name = json.optString("adv_sub_name", "");
        bean.adv_sub_content = json.optString("adv_sub_content", "");
        bean.adv_sub_memo = json.optString("adv_sub_memo", "");
        bean.link_sub_url = json.optString("link_sub_url", "");
        bean.images = json.optString("images", "");
        bean.start_time = json.optLong("start_time", 0);
        bean.end_time = json.optLong("end_time", 0);
        bean.is_used = json.optInt("is_used", 0);
        bean.add_time = json.optLong("add_time", 0);
        bean.add_user = json.optString("add_user", "");
        bean.update_time = json.optLong("update_time", 0);
        bean.update_user = json.optString("update_user", "");
        bean.url = Urls.web + "/" + json.optString("url", "");
        return bean;
    }
}
